/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.project.web.quotedprice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.thinkgem.jeesite.common.service.ActAuditService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.project.entity.quotedprice.ProjectQuotedPrice;
import com.thinkgem.jeesite.modules.project.service.quotedprice.ProjectQuotedPriceService;

/**
 * 工程报价记录Controller
 * @author xiaoming
 * @version 2020-02-16
 */
@Controller
@RequestMapping(value = "${adminPath}/project/quotedprice/projectQuotedPrice")
public class ProjectQuotedPriceController extends BaseController<ProjectQuotedPrice> {

	@Autowired
	private ProjectQuotedPriceService projectQuotedPriceService;

	@Override
	protected ProjectQuotedPriceService getService() {
		return this.projectQuotedPriceService;
	}

	@ModelAttribute
	public ProjectQuotedPrice get(@RequestParam(required=false) String id) {
		ProjectQuotedPrice entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = projectQuotedPriceService.get(id);
		}
		if (entity == null){
			entity = new ProjectQuotedPrice();
		}
		return entity;
	}
	
	@RequiresPermissions("project:quotedprice:projectQuotedPrice:view")
	@RequestMapping(value = {"list", ""})
	public String list(ProjectQuotedPrice projectQuotedPrice, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ProjectQuotedPrice> page = projectQuotedPriceService.findPage(new Page<ProjectQuotedPrice>(request, response), projectQuotedPrice); 
		model.addAttribute("page", page);
		return "modules/project/quotedprice/projectQuotedPriceList";
	}

	@RequiresPermissions("project:quotedprice:projectQuotedPrice:view")
	@RequestMapping(value = "form")
	public String form(ProjectQuotedPrice projectQuotedPrice, Model model) {
		model.addAttribute("projectQuotedPrice", projectQuotedPrice);
		String viewName = "projectQuotedPriceForm";
		if(StringUtils.isNotEmpty(projectQuotedPrice.getId()) &&projectQuotedPrice.getAct().isFinishTask()){
			viewName = "projectQuotedPriceView";
		}else if(StringUtils.isNotEmpty(projectQuotedPrice.getId()) && projectQuotedPrice.getAct().isTodoTask()){
			viewName = "projectQuotedPriceAudit";
		}
		return "modules/project/quotedprice/"+viewName;
	}

	@RequiresPermissions("project:quotedprice:projectQuotedPrice:edit")
	@RequestMapping(value = "save")
	public String save(ProjectQuotedPrice projectQuotedPrice, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, projectQuotedPrice)){
			return form(projectQuotedPrice, model);
		}
		projectQuotedPriceService.save(projectQuotedPrice);
		addMessage(redirectAttributes, "保存工程报价成功");
		return "redirect:"+Global.getAdminPath()+"/project/quotedprice/projectQuotedPrice/?repage";
	}
	
	@RequiresPermissions("project:quotedprice:projectQuotedPrice:edit")
	@RequestMapping(value = "delete")
	public String delete(ProjectQuotedPrice projectQuotedPrice, RedirectAttributes redirectAttributes) {
		projectQuotedPriceService.delete(projectQuotedPrice);
		addMessage(redirectAttributes, "删除工程报价成功");
		return "redirect:"+Global.getAdminPath()+"/project/quotedprice/projectQuotedPrice/?repage";
	}

}